<?php
class sql{
private $url;
function __construct($url){
$this->set_url($url);
}
//return sql
function returnSql($choose){
$url=$this->get_url();
if($choose){
$sqlfile=$url."includes/install/snock.sql";
}else{
$sqlfile=$url."includes/install/snock_data.sql";
}
	
@	$fp=fopen($sqlfile,'r');
@	$sql=fread($fp,filesize($sqlfile));
@	fclose($fp);
	if(empty($sql))
	{
		echo $sqlfile.' 文件丢失,安装不成功';	
		echo ' <br/>请重新上传';
	exit;
	}
	return $sql;
}
//rebuild sql

function checksql($sql){
//$sql=str_replace("\r","\n",$sql);

$ret=array();
	foreach(explode(";\n",trim($sql)) as $query)
	{
	$queries=explode(";\n",trim($query));
	
		foreach($queries as $query)
		{

	// $ret[$num].=$query[0]=='#'||$query[0].$query[1]=='--'?'':$query;
		  
		   $ret[$num].=	trim($query);
		}
		$num++;
	}
	return $ret;
}
//runsql
function runsql($sql){
$url=$this->get_url();
require_once $url.'includes/conn.php';
$line=0;
for($i=0;$i<count($sql);$i++){
$conn =new conn();
@$conn->set_sql($sql[$i]);
@$line+=$conn->get_line();


}
return $line;

}
function set_url($url){
$this->url=$url;
}
function get_url(){
 return $this->url;
}
}
?>